﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Security.Cryptography;
using System.Text;

namespace SMSSnew
{
    public class encryption
    {
        public static SymmetricAlgorithm desObj = Rijndael.Create();
        public static string cipherData;
        public static byte[] cipherbytes;
        public static byte[] plainbytes;
        public static byte[] plainbytes2;
        public static byte[] plainkey;

        public string encrypt(string plainText)
        {
            string encrypetedText = "" ;

            cipherData = plainText;
            plainbytes = Encoding.ASCII.GetBytes(cipherData);
            plainkey = Encoding.ASCII.GetBytes("0123456789abcdef");
            desObj.Key = plainkey;
            desObj.Mode = CipherMode.CBC;
            desObj.Padding = PaddingMode.PKCS7;
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            CryptoStream cs = new CryptoStream(ms, desObj.CreateEncryptor(), CryptoStreamMode.Write);
            cs.Write(plainbytes, 0, plainbytes.Length);
            cs.Close();
            cipherbytes = ms.ToArray();
            ms.Close();
            string encryptedText = Encoding.ASCII.GetString(cipherbytes);

            return encrypetedText;
        }


        //public void decrypt()
        //{
        //    System.IO.MemoryStream ms1 = new System.IO.MemoryStream(cipherbytes);
        //    //  System.IO.MemoryStream ms1 = new System.IO.MemoryStream(TextBox2.Text);

        //    CryptoStream cs1 = new CryptoStream(ms1, desObj.CreateDecryptor(), CryptoStreamMode.Read);

        //    cs1.Read(cipherbytes, 0, cipherbytes.Length);
        //    plainbytes2 = ms1.ToArray();
        //    cs1.Close();
        //    ms1.Close();

        //    TextBox3.Text = Encoding.ASCII.GetString(plainbytes2);
        //}

    }
}
